package com.java.time;

import java.util.Calendar;
import java.util.Date;

public class CalendarAPI {
    public static void main(String[] args) {
        // 创建对象：Calendar是抽象类，Calendar.getInstance()获取的是Calendar子类实例
        Calendar calendar = Calendar.getInstance();
        
        // setTime：设置Date对象
        calendar.setTime(new Date(0));
        
        // getTime：获取Date对象
        System.out.println(calendar.getTime()); // Thu Jan 01 08:00:00 CST 1970
        
        // setTimeInMillis：设置毫秒值
        calendar.setTimeInMillis(1000);
        
        // getTimeInMillis：获取毫秒值
        System.out.println(calendar.getTimeInMillis()); // 1000
        System.out.println(calendar.getTime()); // Thu Jan 01 08:00:01 CST 1970
        
        // set：设置某日期或时间的值
        calendar.set(Calendar.YEAR, 2001);
        calendar.set(Calendar.MONTH, 3);
        calendar.set(Calendar.DATE, 4);
        
        // get：获取某日期或时间的值
        System.out.println(calendar.get(Calendar.YEAR)); // 2001
        System.out.println(calendar.get(Calendar.MONTH)); // 3
        System.out.println(calendar.get(Calendar.DATE)); // 4
        System.out.println(calendar.getTime()); // Wed Apr 04 08:00:01 CST 2001
        
        // add：增加或减少某日期或时间的值
        calendar.add(Calendar.YEAR, -1);
        calendar.add(Calendar.DATE, 4);
        System.out.println(calendar.getTime()); // Sat Apr 08 08:00:01 CST 2000
        
        // ⭐注意：月份范围为0-11，星期范围为1-7但1表示星期日
    }
}
